﻿using EA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.EAUMLSynthesizerPlugin.EAProjects;
using UMLSynthesizer.Tasks;

namespace UMLSynthesizer.EAUMLSynthesizerPlugin
{
    public class Main
    {
        /// <summary>
        /// Name of plugin in the extension menu of Enterprise Architect
        /// </summary>
        const string menuName_Root = "-&UML Synthesizer";
        const string menuName_About = "About";

        /// <summary>
        /// Constructor
        /// </summary>
        public Main()
        { }

        #region EA Interaction

        /// <summary>
        /// Called Before EA starts to check Add-In Exists
        /// </summary>
        /// <param name="repository"></param>
        /// <returns>A simple string</returns>
        public String EA_Connect(Repository repository) { return ""; }

        /// <summary>
        /// Called when user Click Add-Ins Menu item from within EA.
        /// Populates the Menu with our desired selections.
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="location"></param>
        /// <param name="menuName">The name of the parent menu voice</param>
        /// <returns></returns>
        public object EA_GetMenuItems(Repository repository, string location, string menuName)
        {
            Package aPackage = repository.GetTreeSelectedPackage();
            switch (menuName)
            {
                case "":
                    return menuName_Root;
                case menuName_Root: 
                    return new string[] {
                        ClassDiagramEAProject.DisplayName,
                        menuName_About
                    };
            }
            return "";
        }

        /// <summary>
        /// Called once Menu has been opened to see what menu items are active.
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="location"></param>
        /// <param name="menuName"></param>
        /// <param name="itemName"></param>
        /// <param name="isEnabled"></param>
        /// <param name="isChecked"></param>
        public void EA_GetMenuState(Repository repository, string location, string menuName,
            string itemName, ref bool isEnabled, ref bool isChecked)
        {
            isEnabled = true;
        }

        /// <summary>
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="location"></param>
        /// <param name="menuName"></param>
        /// <param name="itemName"></param>
        public void EA_MenuClick(Repository repository, string location, string menuName, string itemName)
        {
            switch (itemName)
            {
                case ClassDiagramEAProject.DisplayName:
                    new ClassDiagramEAProject(repository).StartProject();
                    break;
                case menuName_About:
                    System.Windows.MessageBox.Show(
                        "Tesista:\nDa Corte Mirko\n\n" +
                        "Relatore:\nTasso Carlo\n\n" +
                        "Corelatore:\nBaruzzo Andrea");
                    break;
            }
        }

        #endregion
    }
}
